<?php
class App_Model_SystemActions extends Zend_Db_Table_Abstract
{
    protected $_name = 'core_action';
    protected $_primary = 'id';
    
    public function getRow($module, $controller, $action)
    {
    	$select = $this->select()
                      	->where('module = ?', $module)
                      	->where('controller = ?', $controller)
                      	->where('action = ?', $action);
        return $this->fetchRow($select);
    }
    
    public function getAction($actionid)
    {
    	return $this->find($actionid)->current();
    }
    
    public function getActions($module,$controller=null)
    {
    	if($controller) {
    		$select = $this->select()
                      	->where('module = ?', $module)
                      	->where('controller = ?', $controller);
    	}
    	else {
    		$select = $this->select()
                      	->where('module = ?', $module);
    	}
    	$select->order('controller');
    	
    	return $this->fetchAll($select);
    }
    
    public function getRessources()
    {
    	$select  = "	SELECT	DISTINCT CONCAT(actions.module,':',actions.controller) as ressource    						    							 
    					FROM	actionparams actions";
    	$ressources = Zend_Registry::get('db')->fetchAll($select);
    	return $ressources;
    }
}